import fileUpload from "@/components/file-upload.vue"
import { TypeOptions } from "../constant"
import { checkShop } from "@/apis/shop"
import { checkBill } from "@/apis/bill"
import { batchAddOrder } from "@/apis/order"

export default async (that)=>{
	
	return {
		columns:[],
		reqOptions:{
			insert:{
				custom:{
					callback:(form)=>{
						console.log(form)
						let i = that.tableData.findIndex(item=>item.orderId == form.orderId || item.orderNo == form.orderNo)
						if(i!=-1){
							that.$message.error("订单id或订单号已存在！")
							return
						}
						that.tableData.push(form)
						that.show = false
					}
				}
			},
			update:{
				custom:{
					callback(form){
						console.log("编辑完成",form)
						that.show = false
					}
				}
			},
			remove:{
				custom:{
					callback(form){
						console.log("删除",form)
						let parent = that.$parent
						if(parent.status==1){
							parent.shopArrs = parent.shopArrs.filter(item=>item.shopName!=form.shopName)
							that.tableData = parent.shopArrs
						}else if(parent.status=2){
							that.tableData = that.tableData.filter(item=>item.orderId!=form.orderId)
							parent.shopArrs[parent.currentShop].orderList = parent.shopArrs[parent.currentShop].orderList.filter(item=>item.orderId!=form.orderId)
						}
						console.log(that)
						
					}
				},
			}
		},
		search:{
			form:{
				
			},
			options:[
				// {
				// 	key:"batch1",
				// 	label:"金额替换",
				// 	type:"el-input",
				// 	width:"100px",
				// 	required:true,
				// 	props:{
				// 		type:"number",
				// 		placeholder:"原金额",
				// 		clearable:true
				// 	}
				// },
				// {
				// 	key:"batch2",
				// 	label:"",
				// 	type:"el-input",
				// 	required:true,
				// 	width:"100px",
				// 	props:{
				// 		type:"number",
				// 		placeholder:"替换金额",
				// 		clearable:true

				// 	}
				// },
				// {
				// 	key:"batch3",
				// 	label:"一键替换",
				// 	type:"el-button",
				// 	width:false,
				// 	removeLabel:true,
				// 	props:{
				// 		type:"danger"
				// 	},
				// 	listeners:{
				// 		click(){
				// 			that.searchFun((form)=>{
				// 				console.log(form)
				// 				that.tableData = that.tableData.map(item=>{
				// 					return {
				// 						...item,
				// 						money:Number(item.money)==Number(form.batch1)?form.batch2:item.money
				// 					}
				// 				})
				// 			})
				// 		}
				// 	}
				// },
				// {
				// 	key:"confirmImport",
				// 	type:"el-button",
				// 	removeLabel:true,
				// 	width:false,
				// 	label:"确认导入",
				// 	props:{
				// 		type:"primary"
				// 	},
				// 	listeners:{
				// 		 click(){
				// 			that.$confirm('将导入当前订单到系统，是否继续', '提示', {
				// 				confirmButtonText: '确定',
				// 				cancelButtonText: '取消',
				// 				type: 'warning'
				// 			}).then(async () => {
				// 				console.log("导入")
				// 				//先验证订单相关是否存在
				// 				//去掉重复的数据
				// 				let shopObj = {}
				// 				let billObj = {}
				// 				that.tableData.forEach(item=>{
				// 					shopObj[item.shopName] = {
				// 						shopName:item.shopName,
				// 						platform:TypeOptions.find(type=>type.label==item.platform||type.value == item.platform).value
				// 					}
				// 					billObj[item.bid] = {
				// 						activeDate:item.activeDate,
				// 						billNo:item.bid,
				// 						shopName:item.shopName
				// 					}
				// 				})
				// 				let shopArray = Object.values(shopObj)
				// 				let billArray = Object.values(billObj)
				// 				await checkShop(shopArray)
				// 				await checkBill(billArray)
				// 				await batchAddOrder(that.tableData)
				// 				setTimeout(()=>{
				// 					that.$router.push({
				// 						path:"/bill"
				// 					})
				// 				},1000)
				// 			});
				// 		}
				// 	}
				// },
				// {
				// 	key:"back",
				// 	label:"",
				// 	removeLabel:true,
				// 	slot:"back"
				// }
			],
			direction:"h",
			labelPosition:"right"
		},
		operation:{
			form:{},
			direction:"h",
			options:[
				{
					key:"orderText",
					type:"el-link",
					label:"",
					slot:"orderText",
				},
				{
					key:"addBtn2",
					slot:"addBtn2",
					label:""
				},
				{
					key:"batchChangePrice",
					slot:"batchChangePrice",
					label:""
				},
				{
					key:"batchAddbtn",
					slot:"batchAddbtn",
					label:""
				},
				{
					key:"back",
					label:"",
					removeLabel:true,
					slot:"back"
				},
				{
					key:"blank",
					type:"div",
					label:"  ",
				},
				{
					key:"blank2",
					type:"div",
					label:"  ",
				},
				{
					key:"blank3",
					type:"div",
					label:"  ",
					width:"300px"
				},
				
				{
					key:"errlog",
					label:"",
					removeLabel:true,
					slot:"errlog"
				}
				// {
				// 	key:"addBtn1",
				// 	type:"el-button",
				// 	label:"添加",
				// 	width:false,
				// 	removeLabel:true,
				// 	props:{
				// 		type:"primary",
				// 		size:"mini",
				// 		// icon:"el-icon-plus"
				// 	},
				// 	listeners:{
				// 		click:async (...e)=>{							
							
				// 		}
				// 	}
				// }
			]
		},
		updateField:async (form={})=>{
			return {
				form,
				direction:"h",
				options:[
					
					{
						key:"bid",
						label:"账单编号",
						type:"el-select",
						readStore:"billOption",
						required:true,
						props:{
							filterable:true,
							allowCreate:true
						}
					},
					{
						key:"orderId",
						label:"订单id",
						type:"el-input",
						required:true
					},
					{
						key:"orderNo",
						label:"订单号",
						type:"el-input",
						required:true
					},
					{
						key:"shopName",
						label:"店铺名",
						type:"el-select",
						require:true,
						readStore:"shopOption",
						props:{
							filterable:true,
							allowCreate:true,
						}
					},
					{
						key:"platform",
						label:"所属平台",
						type:"el-select",
						require:true,
						options:TypeOptions,
						props:{
							filterable:true,
							allowCreate:true,
						}
					},
					{
						key:"money",
						label:"每单结算金额",
						type:"el-input",
						required:true,
						props:{
							type:"number"
						}
					},
					{
						key:"amount",
						label:"实付金额",
						type:"el-input",
						required:true,
						props:{
							type:"number"
						}
					},
					{
						key:"nickname",
						label:"微信昵称",
						type:"el-input",
						// required:true
					},
					{
						key:"phone",
						label:"手机尾号",
						type:"el-input",
						// required:true
					},
					{
						key:"orderCreateTime",
						label:"订单创建时间",
						type:"el-date-picker",
						required:true,
						props:{
							type:"datetime",
							format:"yyyy-MM-dd HH:mm:ss",
							"value-format":"yyyy-MM-dd HH:mm:ss"
						},
					},
					{
						key:"imgList",
						label:"订单截图",
						type:fileUpload,
						width:"500px",
						props:{
							actionType:"images/order",
							imageField:"imgList",
							multiple:true
							
						},
						required:true,
					}
                    
				
				]
			}
		},
		config:{
			dialog:{
				top:"3vh"
			},
			table:{
				autoHeight:true,
				show:true,
				checkbox:true
			},
			operation:{
				show:true
			},
			pagination:{
				show:false
			}
		}
        
	}
}